//
//  babySwimViewController.m
//  YuErmuYing
//
//  Created by Tiancheng on 16/8/20.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "babySwimViewController.h"
//网络封装
#import "HttpRequest.h"
//Model
#import "nextActivityModel.h"
#import "UIImageView+WebCache.h"
#import "activityOrderViewController.h"
//跳转界面
#import "tiaoZhuanView.h"
#import "swimToPhoto.h"
#import "xianXiaHuoDongViewController.h"
#import "Macros.h"
#import "adDetailViewController.h"
#import "SVProgressHUD.h"

@interface babySwimViewController ()
//背景色
@property (weak, nonatomic) IBOutlet UIView *backGroundView;
//backScrollView
@property (weak, nonatomic) IBOutlet UIScrollView *backScrollView;

//导航条背景色
@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (weak, nonatomic) IBOutlet UIView *headerView01;
//题目
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
//图片
@property (weak, nonatomic) IBOutlet UIImageView *picImageView;
//字体添加
@property (weak, nonatomic) IBOutlet UILabel *textLabel;
//地理位置
@property (weak, nonatomic) IBOutlet UILabel *textLabel01;
//时间字体
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
//活动详情
@property (weak, nonatomic) IBOutlet UILabel *aictivityLabel;
//儿童票
@property (weak, nonatomic) IBOutlet UILabel *childLabel;
//儿童票开始时间
@property (weak, nonatomic) IBOutlet UILabel *timeLabel01;
//通票
@property (weak, nonatomic) IBOutlet UILabel *tongPiaoLabel;
//通票可用时间
@property (weak, nonatomic) IBOutlet UILabel *timeLabel02;
//儿童票的价格
@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;
//成人的价格
@property (weak, nonatomic) IBOutlet UILabel *moneyLabel01;
//钱币的符号
@property (weak, nonatomic) IBOutlet UILabel *childSymbole;
//钱币的符号
@property (weak, nonatomic) IBOutlet UILabel *adultSymbole;
//儿童点击按钮
@property (weak, nonatomic) IBOutlet UIButton *childButton;
//成人通票按钮
@property (weak, nonatomic) IBOutlet UIButton *tongBtn;
//星星图片1
@property (weak, nonatomic) IBOutlet UIImageView *picStar1;
//星星图片2
@property (weak, nonatomic) IBOutlet UIImageView *picStar2;
//星星图片3
@property (weak, nonatomic) IBOutlet UIImageView *picStar3;
//星星图片4
@property (weak, nonatomic) IBOutlet UIImageView *picStar4;
//接口地址
@property(nonatomic,copy)NSString *urlString1;
//网络数组
@property(nonatomic,copy)NSMutableArray*json_Array;
@property(nonatomic,copy)NSMutableArray*json_Array2;
//装星星的数组
@property(nonatomic,copy)NSMutableArray*starArray;
//新生成的view
@property(nonatomic,retain)UIView *backView;

@end

@implementation babySwimViewController
@synthesize json_Array,starArray,json_Array2;

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=YES;
    self.tabBarController.tabBar.hidden=YES;
}
static float progress = 0.0f;

-(void)viewDidAppear:(BOOL)animated
{
    float custom_height=self.tongBtn.frame.size.height+self.tongBtn.frame.origin.y;
    if (custom_height<screenHeight)
    {
        //backGroundScrollView的最终高度
        self.backScrollView.contentSize=CGSizeMake(0, screenHeight);
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置背景色
    [self setViewColor];
    json_Array=[NSMutableArray array];
    json_Array2=[NSMutableArray array];
    starArray=[NSMutableArray array];
    swimToPhoto *stp=[swimToPhoto shardeManager];
//    if (stp.num==3)
//    {
//        self.urlString1=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/Carousel/product"];
//        [self anotherUpdateDataFromNet];
//    }
//    else
//    {
//    self.
//    float hight=self.headerView01.frame.origin.y+self.headerView01.frame.size.height;

    progress=0.0f;
    [SVProgressHUD showWithStatus:@"加载中请稍后..."];
        [self updateDataFromNet];
    self.backView=[[UIView alloc]initWithFrame:CGRectMake(0, 64, screenWidth, screenHeight-64)];
    self.backView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:self.backView];
//    }
}
-(void)setViewColor
{
    //导航条
    self.headerView.backgroundColor=[UIColor colorWithRed:243/255.0 green:143/255.0 blue:177/255.0 alpha:1.0];
    self.headerView01.backgroundColor=[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0];
    self.backGroundView.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0];
    self.childSymbole.textColor=[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0];
    self.adultSymbole.textColor=[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0];
    self.moneyLabel.textColor=[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0];
    self.moneyLabel01.textColor=[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0];
    [self.childButton setTitleColor:[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0]forState:UIControlStateNormal];
    [self.tongBtn setTitleColor:[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0]forState:UIControlStateNormal];
    //给按钮边框设置颜色
    //设置按钮的边界颜色
    [self.tongBtn.layer setBorderWidth:1.0];
    //边框宽度
    [self.tongBtn.layer setBorderColor:[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0].CGColor];
    [self.childButton.layer setBorderWidth:1.0];
    //边框宽度
    [self.childButton.layer setBorderColor:[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1.0].CGColor];

}
-(void)updateDataFromNet
{
    swimToPhoto *stp=[swimToPhoto shardeManager];
    if (stp.num==1)
    {
    self.urlString1=[NSString stringWithFormat:@"http://112.74.114.1/parenting/index.php/Api/Active/findphoto_info"];
    }
    else if (stp.num==2)
    {
     self.urlString1=[NSString stringWithFormat:@"http://112.74.114.1/parenting/index.php/Api/Active/findall_info"];
    }
    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:self.urlString1 parameters:nil success:^(id responseObject)
     {
         id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         //获取数组
         json_Array=[json objectForKey:@"data"];
//         NSLog(@"json_Array=%@",json_Array);
         if (json_Array.count>0)
         {
             [self dismiss];
//             nam.idString=[json_Array[0] objectForKey:@"active_id"];
//             nam.type=[json_Array[0] objectForKey:@"ticket_type"];
////             [[NSNotificationCenter defaultCenter]postNotificationName:@"idString" object:nil];
//             nam.address =[json_Array[0] objectForKey:@"active_area"];
//             nam.activityDetail=[json_Array[0] objectForKey:@"active_content"];
//             nam.starNum=[json_Array[0] objectForKey:@"active_level"];
//             nam.picString=[json_Array[0] objectForKey:@"active_pic"];
//             nam.timeString=[json_Array[0] objectForKey:@"active_time"];
//             nam.textString=[json_Array[0] objectForKey:@"active_title"];
//             nam.child01String=[json_Array[1]objectForKey:@"ticket_name"];
//             nam.child02String=[json_Array[1]objectForKey:@"ticket_info"];
//             nam.childMoneyString=[json_Array[1]objectForKey:@"ticket_price"];
//
//             nam.adult01String=[json_Array[2]objectForKey:@"ticket_name"];
//             nam.adult02String=[json_Array[2]objectForKey:@"ticket_info"];
//             nam.adultMoneyString=[json_Array[2]objectForKey:@"ticket_price"];
//             
//             self.childButton.tag=[[json_Array[1]objectForKey:@"ticket_id"]integerValue];
//             self.tongBtn.tag=[[json_Array[2]objectForKey:@"ticket_id"]integerValue];
//             
//             self.childLabel.text=nam.child01String;
//             self.timeLabel01.text=nam.child02String;
//             self.moneyLabel.text=nam.childMoneyString;
//             self.tongPiaoLabel.text=nam.adult01String;
//             self.timeLabel02.text=nam.adult02String;
//             self.moneyLabel01.text=nam.adultMoneyString;
//             self.textLabel.text=nam.textString;
//             self.textLabel01.text=nam.address;
//             self.timeLabel.text=nam.timeString;
//             self.aictivityLabel.text=nam.activityDetail;
//             [self changeStarPicture:nam.starNum];
//         }
//         NSURL* imagePath = [NSURL URLWithString:nam.picString];
//         //给一张默认图片，先使用默认图片，当图片加载完成后再替换
//         [self.picImageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
//        NSLog(@"json=%@",json);
         }
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];
}
- (void)increaseProgress
{
    progress += 0.05f;
    [SVProgressHUD showProgress:progress status:@"加载中..."];
    
    if(progress < 1.0f){
        [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.1f];
    } else {
        [self performSelector:@selector(dismiss) withObject:nil afterDelay:0.4f];
    }
}
- (void)dismiss {
    [SVProgressHUD dismiss];
    [self.backView removeFromSuperview];
    [self setNewObject];
}
-(void)setNewObject
{
    nextActivityModel *nam=[nextActivityModel shardeManager];
    nam.idString=[json_Array[0] objectForKey:@"active_id"];
    nam.type=[json_Array[0] objectForKey:@"ticket_type"];
    //             [[NSNotificationCenter defaultCenter]postNotificationName:@"idString" object:nil];
    nam.address =[json_Array[0] objectForKey:@"active_area"];
    nam.activityDetail=[json_Array[0] objectForKey:@"active_content"];
    nam.starNum=[json_Array[0] objectForKey:@"active_level"];
    nam.picString=[json_Array[0] objectForKey:@"active_pic"];
    nam.timeString=[json_Array[0] objectForKey:@"active_time"];
    nam.textString=[json_Array[0] objectForKey:@"active_title"];
    nam.child01String=[json_Array[1]objectForKey:@"ticket_name"];
    nam.child02String=[json_Array[1]objectForKey:@"ticket_info"];
    nam.childMoneyString=[json_Array[1]objectForKey:@"ticket_price"];
    nam.adult01String=[json_Array[2]objectForKey:@"ticket_name"];
    nam.adult02String=[json_Array[2]objectForKey:@"ticket_info"];
    nam.adultMoneyString=[json_Array[2]objectForKey:@"ticket_price"];
    self.childButton.tag=[[json_Array[1]objectForKey:@"ticket_id"]integerValue];
    self.tongBtn.tag=[[json_Array[2]objectForKey:@"ticket_id"]integerValue];
    self.childLabel.text=nam.child01String;
    self.timeLabel01.text=nam.child02String;
    self.moneyLabel.text=nam.childMoneyString;
    self.tongPiaoLabel.text=nam.adult01String;
    self.timeLabel02.text=nam.adult02String;
    self.moneyLabel01.text=nam.adultMoneyString;
    self.textLabel.text=nam.textString;
    self.textLabel01.text=nam.address;
    self.timeLabel.text=nam.timeString;
    self.aictivityLabel.text=nam.activityDetail;
    [self changeStarPicture:nam.starNum];
    
NSURL* imagePath = [NSURL URLWithString:nam.picString];
//给一张默认图片，先使用默认图片，当图片加载完成后再替换
[self.picImageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
//        NSLog(@"json=%@",json);
}
//-(void)anotherUpdateDataFromNet
//{
//    swimToPhoto *stp=[swimToPhoto shardeManager];
//    NSMutableDictionary *parameters=[NSMutableDictionary dictionary];
//    parameters[@"product_name"]=stp.product_nameString;
//    HttpRequest *httpRequest=[HttpRequest sharedInstance];
//    [httpRequest postWithURLString:self.urlString1 parameters:parameters success:^(id responseObject)
//     {
//         id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
//         //获取数组
//         json_Array=[json objectForKey:@"data"];
//         NSLog(@"json_Array=%@",json_Array);
//         nextActivityModel *nam=[nextActivityModel shardeManager];
//         if (json_Array.count>0)
//         {
//             nam.idString=[json_Array[0] objectForKey:@"active_id"];
//             nam.type=[json_Array[0] objectForKey:@"ticket_type"];
//             //             [[NSNotificationCenter defaultCenter]postNotificationName:@"idString" object:nil];
//             nam.address =[json_Array[0] objectForKey:@"active_area"];
//             nam.activityDetail=[json_Array[0] objectForKey:@"active_content"];
//             nam.starNum=[json_Array[0] objectForKey:@"active_level"];
//             nam.picString=[json_Array[0] objectForKey:@"active_pic"];
//             nam.timeString=[json_Array[0] objectForKey:@"active_time"];
//             nam.textString=[json_Array[0] objectForKey:@"active_title"];
//             nam.child01String=[json_Array[1]objectForKey:@"ticket_name"];
//             nam.child02String=[json_Array[1]objectForKey:@"ticket_info"];
//             nam.childMoneyString=[json_Array[1]objectForKey:@"ticket_price"];
//             
//             nam.adult01String=[json_Array[2]objectForKey:@"ticket_name"];
//             nam.adult02String=[json_Array[2]objectForKey:@"ticket_info"];
//             nam.adultMoneyString=[json_Array[2]objectForKey:@"ticket_price"];
//             self.childButton.tag=[[json_Array[1]objectForKey:@"ticket_id"]integerValue];
//             self.tongBtn.tag=[[json_Array[2]objectForKey:@"ticket_id"]integerValue];
//             self.childLabel.text=nam.child01String;
//             self.timeLabel01.text=nam.child02String;
//             self.moneyLabel.text=nam.childMoneyString;
//             self.tongPiaoLabel.text=nam.adult01String;
//             self.timeLabel02.text=nam.adult02String;
//             self.moneyLabel01.text=nam.adultMoneyString;
//             self.textLabel.text=nam.textString;
//             self.textLabel01.text=nam.address;
//             self.timeLabel.text=nam.timeString;
//             self.aictivityLabel.text=nam.activityDetail;
//             [self changeStarPicture:nam.starNum];
//         }
//         NSURL* imagePath = [NSURL URLWithString:nam.picString];
//         //给一张默认图片，先使用默认图片，当图片加载完成后再替换
//         [self.picImageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
//         //        NSLog(@"json=%@",json);
//     } failure:^(NSError *error) {
//         NSLog(@"error=%@",error);
//     }];
//}
//更改星星的图片
-(void)changeStarPicture:(NSString *)number
{
    int num=[number intValue];
    starArray =[NSMutableArray arrayWithObjects:self.picStar1,self.picStar2,self.picStar3,self.picStar4, nil];
    if (num>4)
    {
        num=4;
    }
    for (int i=0;i<num; i++)
    {
        UIImageView *imageView00=starArray[i];
        imageView00.image=[UIImage imageNamed:@"star-click"];
    }
}

//儿童票预定
- (IBAction)onClickOrder01:(id)sender
{
    tiaoZhuanView *tzv=[tiaoZhuanView shardeManager];
    tzv.numViewController=1;
    nextActivityModel *nam=[nextActivityModel shardeManager];
    UIButton *btn=sender;
    nam.ticket_id=[NSString stringWithFormat:@"%ld",btn.tag];
    activityOrderViewController *aovc=[activityOrderViewController new];
    [self.navigationController pushViewController:aovc animated:YES];
}
//成人票预定
- (IBAction)onClickOrder02:(id)sender
{
    tiaoZhuanView *tzv=[tiaoZhuanView shardeManager];
    tzv.numViewController=2;
    nextActivityModel *nam=[nextActivityModel shardeManager];
    UIButton *btn=sender;
    nam.ticket_id=[NSString stringWithFormat:@"%ld",btn.tag];
    activityOrderViewController *aovc=[activityOrderViewController new];
    [self.navigationController pushViewController:aovc animated:YES];
}

//返回按钮
- (IBAction)goBack:(id)sender
{
//    swimToPhoto *stp=[swimToPhoto shardeManager];
//    if (stp.num==3)
//    {
//        //跳到指定的界面
//        for (UIViewController *controller in self.navigationController.viewControllers)
//        {
//            if ([controller isKindOfClass:[adDetailViewController class]])
//            {
//                [self.navigationController popToViewController:controller animated:YES];
//            }
//        }
//    }
//    else
//    {
    [self.navigationController popToRootViewControllerAnimated:YES];
//    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
